package com.smart.milvus.autoconfigure;

import com.smart.milvus.enums.IdType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;


/**
 * <a href="https://github.com/milvus-io/jmilvus/blob/main/docs/SslConfig.md">...</a>
 */
@Data
@ConfigurationProperties(prefix = "spring.milvus")
public class MilvusProperties {

    /**
     * 用户名
     */
    private String userName = "root";

    /**
     * 密码
     */
    private String password = "milvus";

    /**
     * 主机名
     */
    private String host = "127.0.0.1";

    /**
     * 端口
     */
    private Integer port = 19530;

    /**
     * 链接的uri
     */
    private String connectUri;

    /**
     * 链接超时时间
     */
    private Long connectTimeout;

    /**
     * Enables the secure for client channel.
     * enable – true keep-alive
     */
    private Boolean secure = false;

    /**
     * Sets the idle timeout value of client channel. The timeout value must be larger than zero.
     */
    private Long idleTimeout;

    /**
     * Sets the database name.
     */
    private String database = "default";

    /**
     * Sets the token
     */
    private String token;

    /**
     * Set a deadline for how long you are willing to wait for a reply from the server.
     * With a deadline setting, the client will wait when encounter fast RPC fail caused by network fluctuations.
     * The deadline value must be larger than or equal to zero. Default value is 0, deadline is disabled.
     */
    private Long rpcDeadline;

    /**
     * Sets the keep-alive time value of client channel.
     * The keep-alive value must be greater than zero.
     */
    private Long keepAliveTime;

    /**
     * 全局配置
     */
    @NestedConfigurationProperty
    private MilvusConfig globalConfig = new MilvusConfig();

    /**
     * Milvus 配置
     *
     * @author jiangjun
     * @date 2024/06/14
     */
    @Data
    public static class MilvusConfig {
        /**
         * 主键类型
         */
        private IdType idType = IdType.ASSIGN_ID;
        /**
         * 表名前缀
         */
        private String collectionPrefix;
        /**
         * db字段 format
         * <p>
         * 例: `%s`
         * <p>
         * 对主键无效
         */
        private String columnFormat;
        /**
         * db 表 format
         * <p>
         * 例: `%s`
         * <p>
         */
        private String collectionFormat;
        /**
         * entity 的字段(property)的 format,只有在 column as property 这种情况下生效
         * <p>
         * 例: `%s`
         * <p>
         * 对主键无效
         */
        private String propertyFormat;
        /**
         * 表名是否使用驼峰转下划线命名,只对表名生效
         */
        private boolean tableUnderline = true;
        /**
         * 大写命名,对表名和字段名均生效
         */
        private boolean capitalMode = false;
    }
}
